package cn.edu.nuc.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.ssm.controller.page.PageControl;
import cn.edu.nuc.ssm.controller.page.Pager;
import cn.edu.nuc.ssm.controller.page.Pc;
import cn.edu.nuc.ssm.dao.CinemaMapper;
import cn.edu.nuc.ssm.domain.Cinema;
import cn.edu.nuc.ssm.service.interfaces.CinemalService;
@Service
public class CinemalServiceImpl implements CinemalService {
	@Autowired
	private CinemaMapper mapper;
	
	//添加一个影城
	@Override
	public int insert(Cinema cinema) {
		return mapper.insert(cinema);
	}
	//后台分页显示影城信息
	@Override
	public Pager<Cinema> pageList(String cinemaname, int current) {
		PageControl pc = new PageControl();
		Integer currindex = 1;
		if(current != 0){
			currindex = current;
		}
		pc.setCurrentindex(currindex);
		
		//查询总记录数。(如果带有名字，则查询改名字的总记录数。(模糊查询)
		int count = mapper.count("%"+cinemaname+"%");
		pc.setRscount(count);
		//初始化分页参数。
		pc = Pc.dealpage(pc);
		//查询具体内容
		List<Cinema> cinema = mapper.selectCinema("%"+cinemaname+"%",(pc.getCurrentindex()-1)*pc.getPagesize(),
				pc.getCurrentindex()*pc.getPagesize());
		System.out.println("service层集合大小" + cinema.size());
		Pager<Cinema> pager = new Pager<Cinema>();
		pager.setList(cinema);
		pager.setPagectrl(pc);
		return pager;
	}
	//通过影城id查询影城信息
	@Override
	public Cinema selectByFcid(Integer fcid) {
		return mapper.selectByPrimaryKey(fcid);
	}
	 //更新影城信息
	@Override
	public int updateByPrimaryKey(Cinema cinema) {
		return mapper.updateByPrimaryKey(cinema);
	}
	//通过主键删除单个影城信息。
	@Override
	public int deleteByPrimaryKey(Integer fcid) {
		return mapper.deleteByPrimaryKey(fcid);
	}
	
	//查询所有的影城名
	@Override
	public List<Cinema> select() {
		return mapper.select();
	}

}
